package com.zkh.myutils.markup;

import com.zkh.myutils.utils.Assert;
import com.zkh.myutils.utils.StringUtils;

public class DocElement extends Element{
	//文档类型
	private String docType;
	//XML版本
	private String xmlVersion;
	//XML编码
	private String xmlEncoding;
	//是否离线
	private Boolean xmlStandalone;
	private String publicId;
	private String systemId;
	
	/**
	 * 构造方法
	 */
	public DocElement() {
		this(null);
	}
	/**
	 * 构造方法
	 * @param name 元素名称
	 */
	public DocElement(String name) {
		super(name);
	}
	
	/**
	 * 元素toString（含节点和属性）
	 */
	public String toMarkString() {
		StringBuilder sb = new StringBuilder();
		//xml版本
		if(StringUtils.isNotEmpty(xmlVersion)) {
			sb.append("<?xml version=\"").append(xmlVersion).append('"');
			Assert.doIfNotEmpty(xmlEncoding, code->sb.append(" encoding=\"").append(code).append('"'));
			Assert.doIfNotNull(xmlStandalone, sd->sb.append(" xmlStandalone=\"").append(sd).append('"'));
			sb.append("?>\r\n");
		}
		//文档类型
		if(StringUtils.isNotEmpty(docType)) {
			sb.append("<!DOCTYPE ").append(docType);
			Assert.doIfNotEmpty(publicId, pid->sb.append(" PUBLIC \"").append(pid).append('"'));
			Assert.doIfNotEmpty(systemId, sid->sb.append(" \"").append(sid).append('"'));
			sb.append("?>\r\n");
		}
		//返回
		return sb + super.toMarkupString();
	}
	
	public String getDocType() {
		return docType;
	}
	public void setDocType(String docType) {
		this.docType = docType;
	}
	public String getXmlVersion() {
		return xmlVersion;
	}
	public void setXmlVersion(String xmlVersion) {
		this.xmlVersion = xmlVersion;
	}
	public String getXmlEncoding() {
		return xmlEncoding;
	}
	public void setXmlEncoding(String xmlEncoding) {
		this.xmlEncoding = xmlEncoding;
	}
	public Boolean getXmlStandalone() {
		return xmlStandalone;
	}
	public void setXmlStandalone(Boolean xmlStandalone) {
		this.xmlStandalone = xmlStandalone;
	}
	public String getPublicId() {
		return publicId;
	}
	public void setPublicId(String publicId) {
		this.publicId = publicId;
	}
	public String getSystemId() {
		return systemId;
	}
	public void setSystemId(String systemId) {
		this.systemId = systemId;
	}
}
